/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package zombiedefense.util;

import java.util.LinkedList;

/**
 * This class defines a list in which the elements are
 * stored in sorted order.
 * @author Connor Willison
 */
public class PriorityQueue<T extends Comparable> extends LinkedList<T> {

    /**
     * Adds an object to this list.
     * Objects are stored in ascending order from the
     * beginning of the list.
     * @param object 
     */
    public boolean add(T object) {
	if (isEmpty()) {
	    super.add(0,object);
	    return true;
	} else {

	    for (int i = 0; i < size(); i++) {
		//add the object when objects on this list are equal to or greater than it
		//(list is kept in ascending order)
		if (object.compareTo(get(i)) <= 0) {
		    add(i, object);
		    return true;
		}
	    }
	    
	    //if the object hasn't been added yet, then it is greater than all the rest on the list
	    addLast(object);
	}
	
	return false;
    }
}
